package view;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import view.utils.MenuView;
import control.menu.MenuControl;

public class PainelPrincipal extends JFrame implements View {
	
	private static final long serialVersionUID = 1L;
//	private JPanel painel1, painel2, painel3;
//	private JPanel painelFrame, painelFrameCurso, painelFrameCurso1;
	
	private MenuView menuBar;
	
	private JLabel labelImagem;

//	private static JInternalFrame internal2;
//	private static JInternalFrame internalCurso;
	
//	public static JComboBox JComCursoP;

//	public static JTextField textPesquisaTurma;
//	public static JTextField txtCampPesquisa;
//	
//	private static JButton pesquisarTurma;
//	private JButton adddTurma;
//	private JButton sairTurma;
//	private JButton botnPesquisaCurso, botnAdicionarCurso, botnAlteraCurso;
//	public static JButton alterarTurma;
//
//	private JLabel labPesqCurso;
//
//	public static JTable tabResultPesqCurso;
//
//	private JScrollPane SPResultPesqCurso;
//	private JScrollPane ScrollP;
//
//	public static JList listaProfessor;
//
//	JPanelWithBackground background = null;
//
//	public static DefaultListModel modelo;
	private MenuControl controle;

	public PainelPrincipal(ActionListener controle) {
		this.controle = (MenuControl) controle;
		init();
		setupPanel();
		layoutComponents();
		setup();
	}

	private void setup() {
		setTitle("Projeto Controle Academico");
		setJMenuBar(menuBar);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Dimension screenTela = Toolkit.getDefaultToolkit().getScreenSize();
		this.setBounds(0, 0, screenTela.width, screenTela.height - 40);
		this.setResizable(false);
	}

	private void setupPanel() {
//		painel1.setLayout(new FlowLayout(FlowLayout.CENTER));
//		internal2.setLayout(new FlowLayout(FlowLayout.CENTER));
//		painel2.setLayout(new BorderLayout());
//		painel3.setLayout(null);
//		painelFrame.setLayout(new GridLayout(0, 2, 0, 10));
//		painelFrameCurso1.setLayout(new FlowLayout(FlowLayout.CENTER));
//		background = new JPanelWithBackground("src/h.jpg");
//		background.setSize(651, 400);

	}

	private void layoutComponents() {
//		painel1.add(painel2);
//		painel2.add(menuBar);
//		painel1.add(painel3);
//		painel3.add(internal2);
//		painel3.add(internalCurso);
//		painel3.add(background);
//		add(painel1);
		getContentPane().add(labelImagem);
	}

	private void init() {

		menuBar = new MenuView(new MenuControl());
		
		labelImagem = new JLabel(new ImageIcon(getClass()
				.getResource("images/h.jpg")),
				SwingConstants.CENTER);
		labelImagem.setVisible(true);

//		painel1 = new JPanel();
//		painel2 = new JPanel();
//		painel2.setPreferredSize(new Dimension(780, 30));
//		painel3 = new JPanel();
//		painel3.setPreferredSize(new Dimension(780, 500));
//		painel3.setBackground(new Color(255, 255, 255));

//		frameInterna();
//		frameCurso();
	}

	/*private void frameCurso() {
		internalCurso = new JInternalFrame("Pesquisa Curso", true, true, false);
		internalCurso.setSize(550, 260);
		Dimension paneSize = painel3.getSize();
		Dimension screenSize = painel3.getToolkit().getScreenSize();
		internalCurso.setLocation((screenSize.width - paneSize.width) / 8,
				(screenSize.height - paneSize.height) / 10);
		painelFrameCurso = new JPanel();
		painelFrameCurso.setSize(600, 300);
		painelFrameCurso1 = new JPanel();
		painelFrameCurso1.setSize(200, 100);
		painelFrameCurso1.setBorder(BorderFactory.createTitledBorder(null,
				"PESQUISA CURSO", TitledBorder.CENTER,
				TitledBorder.DEFAULT_JUSTIFICATION));
		labPesqCurso = new JLabel("Nome do curso");
		txtCampPesquisa = new JTextField(10);
		botnPesquisaCurso = new JButton("Pesquisar Curso");
		botnPesquisaCurso.addActionListener(controle);
		botnAdicionarCurso = new JButton("Cadastrar Curso");
		botnAdicionarCurso.addActionListener(controle);
		botnAlteraCurso = new JButton("Alterar Curso");
		botnAlteraCurso.addActionListener(controle);

		tabResultPesqCurso = new JTable();
		SPResultPesqCurso = new JScrollPane();
		tabResultPesqCurso
				.setModel(new DefaultTableModel(new Object[][] {},
						new String[] { "Nome", "Carga Horaria", "Cronograma",
								"Valor" }));
		SPResultPesqCurso.setPreferredSize(new Dimension(400, 150));
		SPResultPesqCurso.setViewportView(tabResultPesqCurso);

		internalCurso.add(painelFrameCurso);
		painelFrameCurso.add(labPesqCurso);
		painelFrameCurso.add(txtCampPesquisa);
		painelFrameCurso.add(botnPesquisaCurso);
		painelFrameCurso.add(botnAdicionarCurso);
		painelFrameCurso.add(painelFrameCurso1);
		painelFrameCurso1.add(SPResultPesqCurso);
		painelFrameCurso1.add(botnAlteraCurso);
	}*/

	/*private void frameInterna() {// Turma
		modeloProf();
		internal2 = new JInternalFrame("Cadastrar Turma", true, true, false);
		internal2.setSize(280, 220);
		Dimension paneSize = painel3.getSize();
		Dimension screenSize = painel3.getToolkit().getScreenSize();
		internal2.setLocation((screenSize.width - paneSize.width) / 5,
				(screenSize.height - paneSize.height) / 6);
		painelFrame = new JPanel();
		painelFrame.setSize(200, 200);
		JPanel painelFrameTurma = new JPanel();
		painelFrameTurma.setSize(250, 250);
		painelFrameTurma.setBorder(BorderFactory.createTitledBorder(null,
				"Resultado", TitledBorder.CENTER,
				TitledBorder.DEFAULT_JUSTIFICATION));
		pesquisarTurma = new JButton("Pesquisar");
		pesquisarTurma.addActionListener(controle);
		textPesquisaTurma = new JTextField(13);
		adddTurma = new JButton("Nova Turma");
		adddTurma.addActionListener(controle);
		sairTurma = new JButton("Sair");
		alterarTurma = new JButton("Alterar");
		alterarTurma.addActionListener(controle);
		sairTurma.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Sair();
			}
		});

		internal2.add(pesquisarTurma);
		internal2.add(textPesquisaTurma);
		internal2.add(painelFrameTurma);
		painelFrameTurma.add(ScrollP);
		internal2.add(adddTurma);
		internal2.add(alterarTurma);
		internal2.add(sairTurma);

	}*/

//	private void modeloProf() {
//		modelo = new DefaultListModel();
//		listaProfessor = new JList(modelo);
//		ScrollP = new JScrollPane(listaProfessor);
//		ScrollP.setPreferredSize(new Dimension(250, 80));
//	}

	public void close() {
		dispose();
	}

	public void exibir() {
		setVisible(true);
	}

	/*public static void InternalFrameCurso() {
		internalCurso.setVisible(true);
		internal2.setVisible(false);
	}

	public static void InternalFrameTurma() {
		internalCurso.setVisible(false);
		internal2.setVisible(true);
	}

	public static void InternalFrameProfessor() {
		internalCurso.setVisible(false);
		internal2.setVisible(false);
	}*/

//	public static void metodoLimparCampo() {
//		// ///////////////////////limpar campas da cad_proferssor
//		pesquisarTurma.setText(null);
//	}

	@Override
	public void fechar() {
		dispose();
	}

	/*public static void Sair() {
		internal2.setVisible(false);
		internalCurso.setVisible(false);
	}*/

}
